﻿// JScript 文件

//光纤光路的配置及管理的公共功能

/// <summary>
/// 光交设备枚举
/// </summary>
var enumCtnOBoxType =
	{
	    enumOBOX_JZ    :        -2, //局站
	    enumOBOX_JF    :        -1, //机房
	    
	    enumOBOX_NULL  :        0,  //空
	    
		enumOBOX_ODF   :		1,	//ODF
		enumOBOX_GJJX  :		2,	//光交接箱
		enumOBOX_GFQH  :		3,	//光分纤盒
		enumOBOX_ZHPXX :	    4,	//综合配线箱
		enumOBOX_GLJT  :		5,	//光缆接头
		enumOBOX_GZDH  :		6,	//光终端盒
		enumOBOX_IDF   :		7,	//IDF

        enumOBOX_POS   :        9,  //POS
        enumOBOX_GYHD  :        10, //光用户点 
        //enumOBOX_MPOS  :        11, //附属POS
        //enumOBOX_MGYHD :        12,  //附属光用户点
        
        enumOBOX_YHD   :        13
		
	}

var enumCtnEntLay =
    {
          enumOBOX_JZ    :        -2, //局站
	      enumOBOX_JF    :        -1, //机房
		  enumOBOX_SS    :		  3, //设施
		  enumOBOX_YHD   :		  4  //用户点
    }

var enumCtnGrType =
    {
         enumGr_PUTONG  : 0,  //普通光路
         enumGr_EPON    : 1   //EPON光路
    }
	
//得到实体的类型
	
function GetGjsbTypeVal(enumCtnOBoxTypeVal)
{
    var vEntVal = ""
    switch (enumCtnOBoxTypeVal)
    {
        case enumCtnOBoxType.enumOBOX_JZ:
            vEntVal = "局站";
            break;
        case enumCtnOBoxType.enumOBOX_JF:
            vEntVal = "机房";
            break;
        case enumCtnOBoxType.enumOBOX_ODF:
            vEntVal = "ODF";
            break;
        case enumCtnOBoxType.enumOBOX_IDF:
            vEntVal = "IDF";
            break;
        case enumCtnOBoxType.enumOBOX_GJJX:
            vEntVal = "光交接箱";
            break;
        case enumCtnOBoxType.enumOBOX_GFQH:
            vEntVal = "光分纤盒";
            break;
        case enumCtnOBoxType.enumOBOX_ZHPXX:
            vEntVal = "综合配线箱";
            break;
        case enumCtnOBoxType.enumOBOX_GZDH:
            vEntVal = "光终端盒";
            break;
        case enumCtnOBoxType.enumOBOX_POS:
            vEntVal = "光分路器";
            break;   
        case enumCtnOBoxType.enumOBOX_GYHD:
            vEntVal = "光用户点";
            break;    
        default:
            vEntVal = "错误的设备类型";
            break;
    }
    return vEntVal
}

//光纤光路配置toolid

var m_Tool = 
{
    //系统控制项
    GRTYPE    : 1001,        //光路类型
    CFGTYPE   : 1002,        //光路配置类型 即有无定单 有定单那么定单是什么类型
    ISIRP     : 1003,        //是不是IRP资源配置系统
    
    //查询条件配置项
    EXP_QUEGR     : 1005,    //查询普通光路的查询条件字段配置信息
    EXP_QUEEPGR   : 1007,    //查询EPON光路的查询条件字段配置信息
    EXP_QUEGD     : 1010,    //查询工单的条件字段配置信息
    EXP_QUEEPGD   : 1015,    //查询EPON光路工单的条件字段配置信息
    
    
    
    //查询结果显示的列信息配置项
    FLD_QUEGR     : 1006,    //普通光路查询结果中显示的字段信息
    FLD_QUEEPGR   : 1008,    //EPON光路查询结果中显示的字段信息
    FLD_QUEGD     : 1011,    //工单查询结果中显示的字段信息
    FLD_QUEGL     : 1012,     //光路承载光缆查询结果中显示的字段信息
    FLD_QUEEPGD   : 1016    //EPON工单查询结果中显示的字段信息
    
}

function GetEnttype(etype)
{
    var objRes = {};
    switch(parseInt(etype))
    {
        case enumCtnOBoxType.enumOBOX_JZ:
            objRes = {maj:1,min:10};
            break;
        case enumCtnOBoxType.enumOBOX_JF:
            objRes = {maj:1,min:11};
            break;
        case enumCtnOBoxType.enumOBOX_ODF:
            objRes = {maj:1,min:87};
            break;
        case enumCtnOBoxType.enumOBOX_IDF:
            objRes = {maj:1,min:88};
            break;
        case enumCtnOBoxType.enumOBOX_GJJX:
            objRes = {maj:1,min:51};
            break;
        case enumCtnOBoxType.enumOBOX_GFQH:
            objRes = {maj:1,min:52};
            break;
        case enumCtnOBoxType.enumOBOX_ZHPXX:
            objRes = {maj:1,min:53};
            break;
        case enumCtnOBoxType.enumOBOX_GZDH:
            objRes = {maj:1,min:50};
            break;
        case enumCtnOBoxType.enumOBOX_POS:
            objRes = {maj:1,min:54};
            break;   
        case enumCtnOBoxType.enumOBOX_GYHD:
            objRes = {maj:1,min:57};
            break;    
        default:
            throw "错误的设备类型"; 
            break;
    }
    return objRes;
}

function GetGjsbSrc(enumCtnOBoxTypeVal, bsel)
{
    var vSrc = ""

    switch (enumCtnOBoxTypeVal)
	{
	    case enumCtnOBoxType.enumOBOX_JZ:
	          vSrc = bsel ? "../Images/Gqgr/Sel_JZ.GIF" : "../Images/Gqgr/JZ.GIF";
	          break;
	    case enumCtnOBoxType.enumOBOX_JF:
	          vSrc = bsel ? "../Images/Gqgr/Sel_JF.GIF" : "../Images/Gqgr/JF.GIF";
	          break;
	    case enumCtnOBoxType.enumOBOX_ODF:
	        vSrc = bsel ? "../Images/Gqgr/Sel_ODF.GIF" : "../Images/Gqgr/ODF.GIF";
	       
	        break;
	    case enumCtnOBoxType.enumOBOX_IDF:
	       vSrc = bsel ? "../Images/Gqgr/Sel_IDF.GIF" : "../Images/Gqgr/IDF.GIF";
	       
	        break;
	    case enumCtnOBoxType.enumOBOX_GJJX:
	        vSrc = bsel ? "../Images/Gqgr/Sel_GJ.GIF" : "../Images/Gqgr/GJ.GIF";
	       
	        break;
	    case enumCtnOBoxType.enumOBOX_GFQH:
	        vSrc = bsel ? "../Images/Gqgr/Sel_GF.GIF" : "../Images/Gqgr/GF.GIF";
	      
	        break;
	    case enumCtnOBoxType.enumOBOX_ZHPXX:
	        vSrc = bsel ? "../Images/Gqgr/Sel_ZHX.GIF" : "../Images/Gqgr/ZHX.GIF";
	       
	        break;
	    case enumCtnOBoxType.enumOBOX_GZDH:
	        vSrc = bsel ? "../Images/Gqgr/Sel_GB.GIF" : "../Images/Gqgr/GB.GIF";
	       
	        break;
	    case enumCtnOBoxType.enumOBOX_POS:
//	    case enumCtnOBoxType.enumOBOX_MPOS:
	        vSrc = bsel ? "../Images/Gqgr/Sel_POS.GIF" : "../Images/Gqgr/POS.GIF";
	        
	        break;
	    case enumCtnOBoxType.enumOBOX_GYHD:
//	    case enumCtnOBoxType.enumOBOX_MGYHD:
	        vSrc = bsel ? "../Images/Gqgr/Sel_ONU.GIF" : "../Images/Gqgr/ONU.GIF";
	       
	        break;
	    default:
	        break;
	}
	return vSrc
}

//得到系统配置参数   光路类型,   定单类型  id为空表示得到所有

function GetSysCfg(id)
{
    var Res = {};
    var cfgFile = "/cfg/GqGrFun.xml?" + new Date().getTime();
    var xmlDoc = CtnTrans.getXml(cfgFile);
    top.CtnXML.clearSpace(xmlDoc);
    
    var nodes = xmlDoc.selectNodes("items/item");
    for(var i = 0; i < nodes.length; i++)
    {
        var nodetype = $XML(nodes[i],"type");
        if(nodetype == "ctr")
        {
             var nodeid = $XML(nodes[i],"id");
             if(!id || parseInt(nodeid) == parseInt(id))
             {
                 Res[$XML(nodes[i],"name")] = $XML(nodes[i],"val");
             }
        }
    }
    return Res;
}

//根据id得到查询配置项

function GetQueCfg(id)
{
    var Res = new Array();
    var cfgFile = "/cfg/GqGrFun.xml?" + new Date().getTime();
    var xmlDoc = CtnTrans.getXml(cfgFile);
    top.CtnXML.clearSpace(xmlDoc);
    
    var nodes = xmlDoc.selectNodes("items/item");
    for(var i = 0; i < nodes.length; i++)
    {
        var nodetype = $XML(nodes[i],"type");
        if(nodetype == "que")
        {
             var nodeid = $XML(nodes[i],"id");
             if(parseInt(nodeid) == parseInt(id))
             {
                 var fldnodes = nodes[i].selectNodes("fld");
                 for(var j = 0; j < fldnodes.length; j++)
                 {
                     var obj = {}
                     obj["maj"] = $XML(fldnodes[j],"maj");
                     obj["min"] = $XML(fldnodes[j],"min");
                     obj["val"] = $XML(fldnodes[j],"val");
                     obj["vis"] = $XML(fldnodes[j],"vis"); 
                     obj["aliasname"] = $XML(fldnodes[j]);
                     
                     Res[j] = obj;
                 }
                 
                 break;
             }
        }
    }
    return Res;
}


    function CopyTextVal(textval)
    {
       var vData = document.getElementById("CopyText")
       if(!vData)
	   {
          obj = document.createElement("INPUT")
	      obj.id="CopyText"
          obj.type="text"
          obj.style.visibility = "hidden"
          document.body.appendChild(obj);   
       }
       obj.value = textval
       
       obj.select();
       objcopy = obj.createTextRange();
       objcopy.execCommand('Copy');
    }


//得到通过局向光纤连接两设备的中间设备  ////-----start


function GetMiddleSb(qsent,zzent,qx,fun)
{
     var serverUrl = "_method=GetMiddleSb"
                               + "&qsent=" + escape(qsent)
                               + "&zzent=" + escape(zzent);
                                        
     var vXml = CtnTrans.getXml("/main.ashx?", "post", serverUrl)
     top.CtnXML.clearSpace(vXml);
     if (!CtnError.validate(vXml))
     {
         CtnError.show();
         return false;
     }
     
     var nodes = vXml.selectNodes("items/item");
     
     if(nodes.length == 0)
     {
         fun(false);
         return false;
     }
     
     if(nodes.length == 1)
     {
         var bmnode = nodes[0].selectNodes("bm");
         var middlebm = $XML(bmnode[0]);
         var entlist = qsent + "|" + middlebm + "|" + zzent;
         // GrType,entlist,qsenttype,zzenttype,Qx,bjump,bcheck,fun
         var params = [0,entlist,3,3,qx,false,1,fun]; 
         top.ExecuteATool(top.m_vt.FUN_SELJXGQ,params);
         return true;
     }
     
     window.list_sel = new CtnListCtrl("list_sel");
     
     
      var params = {
                        title: "选择插入的设备",
                        bmax: false,
                        bmin:true,
                        width:400,
                        height:300,
                        bmodal: true,
                        bresize:false,
                        arrbtn: [{text:" 确 定  ", onClick:function(dlg){dispdevlist(dlg);}},{text:"  关 闭", onClick:function(dlg){dlg.close();fun(false,true);}}]
                     }
           
      // var sel_Dlg = CtnDlg.show("<table><tr><td id='seldevctr'></td></tr></table>",params);  
       var sel_Dlg = new CtnDlgCtrl();
        sel_Dlg.content = "<table><tr><td id='seldevctr'></td></tr></table>";
        sel_Dlg.bmodal = true;
        sel_Dlg.init(params);
        sel_Dlg.open();
        
        
       window.list_sel.create("seldevctr");     
       sel_Dlg.wnd = window;
       sel_Dlg.resfun = fun;
       sel_Dlg.qsent = qsent;
       sel_Dlg.zzent = zzent;
       
       window.list_sel.bscheck = 1;
       window.list_sel.sel_qx = qx;
       window.list_sel.sel_rowno = null;
       //top.list_sel.$ = function(id){return top.$(id);}
       
       window.list_sel.onCheck  = check_sel.bind(window.list_sel); 
       window.list_sel.ballcheck = false;
       window.list_sel.reset();
       var rootNode = null;
        if (vXml.childNodes[0].nodeName != "xml")
        {
            rootNode = vXml.childNodes[0];
        }
        else if (vXml.childNodes.length > 1)
        {
            rootNode = vXml.childNodes[1];
        }
       window.list_sel.insertNode(rootNode, 1);
       
       window.list_sel.show();            

       
}

//向前插入的设备列表

function dispdevlist(dlg)
{
    var resfun = dlg.resfun;
    var qsent = dlg.qsent;
    var zzent = dlg.zzent;
    var qx = window.list_sel.sel_qx;
    
    if(window.list_sel.sel_rowno == null)
    {
        CtnDlg.msg("请选择一个设备！");
        return;
    }
    dlg.close();
    
    var entlist = qsent + "|" + window.list_sel.getCell(window.list_sel.sel_rowno, 0).bm + "|" + zzent;
        
    var params = [0,entlist,3,3,qx,false,1,resfun]; 
    top.ExecuteATool(top.m_vt.FUN_SELJXGQ,params);
    return true;
}


function check_sel(rowno,bchecked)
{
     if(bchecked)
     {
         this.sel_rowno = rowno;
     }
     else
     {
         this.sel_rowno = null;
     }
}

//得到通过局向光纤连接两设备的中间设备  ////-----end


//////////////////////////////条件查询类  start/////////////////////

function colinfo()
{
    this.name = "";
    this.aliasname = "";
    this.defval = "";
    this.disporder = "";
    this.disptype = ""; 
    this.datatype = "";
    this.bdisp = false;
}

var CtnQue = Class.create();


CtnQue.prototype =  
{

    initialize: function() 
    {
         var tmp = $A(arguments)
         var options = tmp.shift()
         
         this.id        = options.id     ? options.id       : "_Que";                //存放查询控件的容器id
         this.name      = options.name   ? options.name     : "_Que";                //对象name
         this.toolid    = options.toolid ? options.toolid   : 1005;                  //查询条件的toolid
         this.zIndex    = options.zIndex ? options.zIndex   : 10;                    //层id
         this.w         = options.w      ? options.w        : 120;                   //每个单元控件的宽度
         this.totalW    = options.totalW      ? options.totalW : null;    
         
         this.fun       = options.fun    ? options.fun      : null;                  //得到构造好的sql条件,回调
         
         this.m_cfg     = "";                                                        //配置文件中得到的配置信息
         this.m_fldlist    = new Array();                                               //字段信息列表
         this.colhtml      = new Array(); 
	     this.colaliasval  = new Array();
	     this.colval       = new Array(); 
         
         this.html      = "";
         this.sqlexp    = "";
         
         this.createhtml();
         
         //window.onresize = function(){this.constructHtml();this.disp();}.bind(this);                    //窗口重绘
    }
    //public
    ,
    disp             :   disp_QUE
    ,
    insertExpbefore  :   insertExpbefore_QUE  //在查询控件前插入自定义控件
    ,
    
    insertExpafter   :   insertExpafter_QUE   //在查询控件前插入自定义控件
    ,
    //private
    
    createhtml       :   createhtml_QUE 
    ,
    initfldlist      :   initfldlist_QUE 
    ,
    bDispCol         :   bDispCol_QUE
    ,
    bDataType        :   bDataType_QUE
    ,
    GetColVal        :   GetColVal_QUE
    ,
    GetDefVal        :   GetDefVal_QUE
    ,
    GetDispType      :   GetDispType_QUE
    ,
    onselchange      :   onselchange_QUE
    ,
    setcoldisp       :   setcoldisp_QUE
    ,
    create           :   create_QUE
    ,
    getsql           :   getsql_QUE
    ,
    constructHtml    :   constructHtml_QUE
}
//public fun start

function disp_QUE()
{
    var dispobj = $(this.id)
    if(dispobj)
    {
       dispobj.innerHTML = this.html;
    }
}

function insertExpbefore_QUE()
{

}

function insertExpafter_QUE()
{

}

//public fun end


//private fun start

function bDispCol_QUE(maj,min,colname)
{
    var res = false;
    for(var i = 0; i < this.m_cfg.length; i++)
    {
         if(this.m_cfg[i].min == min && this.m_cfg[i].maj == maj && colname == this.m_cfg[i].val)
         {
             res = true;
             break;
         }
    }
    return res;
}

function initfldlist_QUE()
{
    //得到配置项
	this.m_cfg = GetQueCfg(this.toolid);
	var xml = "<?xml version='1.0' encoding='gb2312' ?><items>";
	var pre = "";
	for(var i = 0; i < this.m_cfg.length; i++)
	{
	    if(this.m_cfg[i].min != pre)
	    {
	        xml += "<item><maj>" + this.m_cfg[i].maj + "</maj>"
	             + "<min>" + this.m_cfg[i].min + "</min>"
	             + "</item>";
	    }
	    pre = this.m_cfg[i].min;
	}
	xml += "</items>";
	
	
	var serverUrl = "_method=GetFldInfo&tabinfo=" + escape(xml);               
    var vXmlDoc = top.CtnTrans.getXml("/main.ashx?", "post", serverUrl)
     
    //存储字段信息
    var nodes = vXmlDoc.selectNodes("items/item");
    for(var i = 0; i < nodes.length; i++)
    {
        var obj = {};
        obj.maj = $XML(nodes[i],"maj");
        obj.min = $XML(nodes[i],"min");
        var col = new Array();
        
        var colnodes = nodes[i].selectNodes("fld");
        for(var j = 0; j < colnodes.length; j++)
        {
            var acolinfo = new colinfo();
            acolinfo.name      = $XML(colnodes[j],"colname");
	        acolinfo.aliasname = $XML(colnodes[j],"aliasname");
	        acolinfo.defval    = $XML(colnodes[j],"defval");
	        acolinfo.disporder = $XML(colnodes[j],"disporder");
	        acolinfo.disptype  = $XML(colnodes[j],"disptype");
	        acolinfo.datatype  = $XML(colnodes[j],"datatype");
	        acolinfo.bdisp     = this.bDispCol(obj.maj,obj.min,acolinfo.name);
	        col.push(acolinfo);
        }
        obj.col = col;
        
        this.m_fldlist.push(obj);
    }

}

function bDataType_QUE(maj,min,colname)
{
     var res = false;
	 for(var i = 0; i < this.m_fldlist.length; i++)
	 {
	     var colobj = this.m_fldlist[i];
	     
	     if(colobj.maj == maj && colobj.min == min)
	     {
	         var j = 0;
	         for(j = 0; j < colobj.col.length; j++)
	         {
	             if(colname == colobj.col[j].name)
	             {
	                 if("8" == colobj.col[j].datatype || "9" == colobj.col[j].datatype)
	                       res = true;
	                 break;
	             }
	         }
	         if(j < colobj.col.length)
	             break;
	     }
	     
	 }
	 
	 return res;
}


//得到已知列的值
		
		function GetColVal_QUE(maj,min,colname,defval)
		{
		   var serverUrl = "_method=GetColVal&maj=" + escape(maj) + "&min=" + escape(min) + "&colname=" + escape(colname) ;                
           var vXmlDoc = top.CtnTrans.getXml("/main.ashx?", "post", serverUrl);
		   
		   var nodes = vXmlDoc.selectNodes("items/item");
		   var html = "<select style='width:120px;' id='" + maj + "_" + min + "_" + colname + "_val'>"
		   for(var i =0; i < nodes.length; i++)
		   {
		       if(defval == $XML(nodes[i],"dbval"))
		       {
		            html += "<option value='"+$XML(nodes[i],"dbval")+"' selected='selected'>" + $XML(nodes[i],"dispval") + "</option>";
		       }
		       else
		       {
		            html += "<option value='"+$XML(nodes[i],"dbval")+"'>" + $XML(nodes[i],"dispval") + "</option>";
		       }
		   }
		   html += "</select>";
		   return html;
		}
		
		function GetDefVal_QUE(maj,min,colname)
		{
		     var defval = "";
		     for(var i = 0; i < this.m_fldlist.length; i++)
		     {
		         var colobj = this.m_fldlist[i];
		         
		         if(colobj.maj == maj && colobj.min == min)
		         {
		             var j = 0;
		             for(j = 0; j < colobj.col.length; j++)
		             {
		                 if(colname == colobj.col[j].name)
		                 {
		                     defval = colobj.col[j].defval;
		                     
		                     break;
		                 }
		             }
		             if(j < colobj.col.length)
		                 break;
		         }
		         
		     }
		     
		     return defval;
		}
		
		function GetDispType_QUE(maj,min,colname)
		{
		    var disptype = "1";
		
		    for(var i = 0; i < this.m_fldlist.length; i++)
		     {
		         var colobj = this.m_fldlist[i];
		         
		         if(colobj.maj == maj && colobj.min == min)
		         {
		             var j = 0;
		             for(j = 0; j < colobj.col.length; j++)
		             {
		                 if(colname == colobj.col[j].name)
		                 {
		                     disptype = colobj.col[j].disptype;
		                     
		                     break;
		                 }
		             }
		             if(j < colobj.col.length)
		                 break;
		         }
		         
		     }
		     
		     return disptype;
		}
		
		function setcoldisp_QUE(maj,min,oldcol,newcol)
		{
		     for(var i = 0; i < this.m_fldlist.length; i++)
		     {
		         var colobj = this.m_fldlist[i];
		         
		         if(colobj.maj == maj && colobj.min == min)
		         {
		             var j = 0;
		             for(j = 0; j < colobj.col.length; j++)
		             {
		                 if(oldcol == colobj.col[j].name)
		                 {
		                     colobj.col[j].bdisp = false;
		                 }
		                 else if(newcol == colobj.col[j].name)
		                 {
		                     colobj.col[j].bdisp = true;
		                 }
		             }
		             break;
		         }
		         
		     }
		
		}
		
		
		//切换列名
		
		function onselchange_QUE(selobj)
		{
		    var colname = selobj.value;
		    var tdobj = $(selobj.id + "_val").parentNode;
		    
		    var vsplit = selobj.id.split("_");
		    
		    var maj = vsplit[0];
		    var min = vsplit[1];
		    var oldcol = vsplit[2];
		    
		    selobj.id = maj + "_" + min + "_" + colname;
		    
		    var defval = this.GetDefVal(maj,min,colname);
		    
		    if(this.GetDispType(maj,min,colname) == "1")
		    {
		        if(this.bDataType(maj,min,colname))
		        {
		            tdobj.innerHTML = "<input style='width:"+this.w+"px;' id='" + maj + "_" + min + "_" + colname + "_val' type='text' onclick='new Calendar().show(this);' value='"+defval+"'/>";
		        }
		        else
		        {
		            tdobj.innerHTML = "<input style='width:"+this.w+"px;' id='" + maj + "_" + min + "_" + colname + "_val' type='text' value='"+defval+"'/>";
		        }
		    }
		    else
		    {
		        tdobj.innerHTML = this.GetColVal(maj,min,colname,defval);
		    }
		    
		    //设置当前显示的字段
		    
		    this.setcoldisp(maj,min,oldcol,colname);
		}
		
		
		
function create_QUE()
{
     //var expctr = $(this.id);
		    
	 var k = 0;
	 this.colhtml[k]     = ""; 
	 this.colaliasval[k] = ""; 
	 this.colval[k]      = "";
	 
	 for(var i = 0; i < this.m_fldlist.length; i++)
	 {
	      var colobj = this.m_fldlist[i];
	      
	      var tmpcol = "";
	      var start = k;
	      for(var j = 0; j < colobj.col.length; j++)
	      {
	      
	          
	          if(colobj.col[j].bdisp)
	          {
	             if(colobj.col[j].disptype == "1")   //text
	             {
	                 if(this.bDataType(colobj.maj,colobj.min,colobj.col[j].name))
	                 {
	                     this.colval[k] = "<td><input style='width:"+this.w+"px;' id='" + colobj.maj + "_" + colobj.min + "_" + colobj.col[j].name + "_val' type='text' onclick='new Calendar().show(this);' value='"+colobj.col[j].defval+"'/></td>";

	                 }
	                 else
	                 {
	                     this.colval[k] = "<td><input style='width:"+this.w+"px;' id='" + colobj.maj + "_" + colobj.min + "_" + colobj.col[j].name + "_val' type='text' value='"+colobj.col[j].defval+"'/></td>";
	                 }
	             }
	             else
	             {
	                 this.colval[k] = "<td>" + this.GetColVal(colobj.maj,colobj.min,colobj.col[j].name,colobj.col[j].defval) + "</td>";
	             }
	             this.colaliasval[k] = "<td align='right'><select style='width:"+this.w+"px;' id='" + colobj.maj + "_" + colobj.min + "_" + colobj.col[j].name + "' onchange='"+this.name+".onselchange(this)'>";
	           
	             this.colhtml[k] = "<option value='"+colobj.col[j].name+"' selected='selected'>" + colobj.col[j].aliasname + "</option>";
	            
	             k++;
	          }
	          else
	          {
	             tmpcol += "<option value='"+colobj.col[j].name+"'>" + colobj.col[j].aliasname + "</option>";
	          }
	      } 
	      
	      for(var l = start; l < k; l++)
	      {
	          this.colhtml[l] += tmpcol;
	      }
	 }
	 
	 //构造html
     this.constructHtml()
}

function constructHtml_QUE()
{
     var bodyWidth = this.totalW;
    
     if(this.totalW == null)
    {  
	    if(CtnBrowser.IE) bodyWidth  = document.getElementsByTagName("body")[0].clientWidth;
        else if(CtnBrowser.FF)bodyWidth  = document.documentElement.clientWidth;
    }
     var icount = parseInt((bodyWidth/this.w)/2);
     this.html         = "<table style='width:99.8%;'>";
     
	 for(var i = 0; i < this.colhtml.length; i=i+icount)
	 {
	     this.html += "<tr>";
	     for(var j = i; j < i + icount; j++)
	     {
	           if(j < this.colhtml.length)
	               this.html += this.colaliasval[j] + this.colhtml[j] + "</select></td>" + this.colval[j];
	     }
	     this.html +=  "</tr>";
	 }
	 this.html += "<tr><td colspan='"+2*icount+"' align='center'><input type='button' class='button' onclick='"+this.name+".getsql();' value='模糊查询'/></td></tr>"
	 this.html += "</table>";
}

function createhtml_QUE()
{
     //初始化字段列表
     this.initfldlist();
     
     //生成html        
     this.create()
}


function getsql_QUE()
{
     //得到sql
     var sqlArr = new Array();
     
     for(var i = 0; i < this.m_fldlist.length; i++)
	 {
	    var colobj = this.m_fldlist[i];
	    var sqlobj = {};
	    var maj = colobj.maj;
	    var min = colobj.min;
	    var exp = "";
	    
	    sqlobj.maj = maj;
	    sqlobj.min = min;
	   
	    for(var j = 0; j < colobj.col.length; j++)
	    {
	        if(colobj.col[j].bdisp)
	        {
	            var col = $(maj+"_"+min+"_"+colobj.col[j].name).value;
	            var val = $(maj+"_"+min+"_"+colobj.col[j].name+"_val").value;
	            if(val.length > 0)
	            {
	                if(exp == "")
	                {
	                   exp = col + " like '%" + val + "%'";
	                }
	                else
	                {
	                  exp += " and " + col + " like '%" + val + "%'";
	                }
	            }
	        }
	    }
	    sqlobj.exp = exp;
	    sqlArr.push(sqlobj);
	    
	 }
     
     
     //回调
     if(this.fun)
     {
         this.fun(sqlArr);
     }
}



//private fun end





//////////////////////////////条件查询类  end//////////////////////////


//转换图形路由的xml---》数据路由的xml 

function ConvertGraphToData_LY(xml,bm)
{
     var Res = "<items><colnames><xh>序号</xh><adbm>A端设备</adbm><addz>A端端子</addz><adglmc>A端光缆</adglmc><bdbm>B端设备</bdbm><bdkh>B端端子</bdkh><bdglmc>B端光缆</bdglmc></colnames>";
     var XmlDoc = CtnXML.getXmlDoc();
     
     if (xml.indexOf("<?xml") == -1)
    {
        xml = "<?xml version='1.0' encoding='gb2312' ?> " + xml;
    }
    try
    {
        XmlDoc.loadXML(xml);
    }
    catch (e)
    {
        CtnDlg.msg("xml数据不符合规范！");
        return false;
    }
    
    var nodes = XmlDoc.selectNodes("Items/Item")
    
    for(var i = 0; i < nodes.length; i++)
    {
        var node = nodes[i];
        
        var grbm = $XML(node,"grbm");
        
        if(bm == grbm)
        {
            var lynodes = node.selectNodes("LY");
            for(var j = 0; j < lynodes.length; j++)
            {
                var lynode = lynodes[j];
                var addz = $XML(lynode,"adkh").length > 0 ? $XML(lynode,"adkh") + "/" + $XML(lynode,"addz") : $XML(lynode,"addz");
                var bddz = $XML(lynode,"bdkh").length > 0 ? $XML(lynode,"bdkh") + "/" + $XML(lynode,"bddz") : $XML(lynode,"bddz");
                
                Res += "<item>";
                Res += "<xh>" + $XML(lynode,"xh") + "</xh>";
                Res += "<adsb>" + $XML(lynode,"adbm") + "(" +$XML(lynode,"admc") +")" + "</adsb>";
                Res += "<addz>" + addz + "</addz>";
                Res += "<adgl>" + $XML(lynode,"adglmc") + "</adgl>";
                Res += "<bdsb>" + $XML(lynode,"bdbm") + "(" +$XML(lynode,"bdmc") +")" + "</bdsb>";
                Res += "<bddz>" + bddz + "</bddz>";
                Res += "<bdgl>" + $XML(lynode,"bdglmc") + "</bdgl>";
                Res += "</item>";
            }
            break;
        }  
    }
    Res += "</items>";
    return Res;
}

function ConvertDataToListData_Ly(xml)
{
    var Res = "<items><colnames><xh>序号</xh><adbm>A端设备</adbm><addz>A端端子</addz><adglmc>A端光缆</adglmc><bdbm>B端设备</bdbm><bdkh>B端端子</bdkh><bdglmc>B端光缆</bdglmc></colnames>";
    var XmlDoc = CtnXML.getXmlDoc();
     
    if (xml.indexOf("<?xml") == -1)
    {
        xml = "<?xml version='1.0' encoding='gb2312' ?> " + xml;
    }
    try
    {
        XmlDoc.loadXML(xml);
    }
    catch (e)
    {
        CtnDlg.msg("xml数据不符合规范！");
        return false;
    }
    
    var nodes = XmlDoc.selectNodes("items/item")
    var flag = true;
    if(!IsDsQ(xml))
    {
        flag = false
    }
    for(var i = 0; i < nodes.length; i++)
    {
        var node = nodes[i];
        
        
        var lynodes = node.selectNodes("ly");

        var Xh = 0;
        for(var j = 0; j < lynodes.length; j++)
        {
            if(flag == true)
            {
                if(parseInt(j)%2 == 0)
                {
                    Xh = parseInt(Xh) + 1;
                }
            }
            else
            {
                Xh = parseInt(Xh) + 1;
            }
            
            var lynode = lynodes[j];
  
            var AdkhNd = lynode.selectNodes("adkh")
            var BdkhNd = lynode.selectNodes("bdkh")
            var AdDzNd = lynode.selectNodes("addz")
            var BdDzNd = lynode.selectNodes("bddz")
            var AdBmNd = lynode.selectNodes("adbm")
            var BdBmNd = lynode.selectNodes("bdbm")
            var AdMcNd = lynode.selectNodes("admc")
            var BdMcNd = lynode.selectNodes("bdmc")
            var AdglNd = lynode.selectNodes("adglmc")
            var BdglNd = lynode.selectNodes("bdglmc")
            var AdQxNd = lynode.selectNodes("adglqx")
            var BdQxNd = lynode.selectNodes("bdglqx")
            var addz = $XML(AdkhNd[0]) != undefined  ? $XML(AdkhNd[0]) + "/" + $XML(AdDzNd[0]) : $XML(AdDzNd[0]);
            var bddz = $XML(BdkhNd[0]) != undefined  ? $XML(BdkhNd[0]) + "/" + $XML(BdDzNd[0]) : $XML(BdDzNd[0]);
            var adgl = $XML(AdglNd[0]) != undefined  ? $XML(AdglNd[0]) + "(" +$XML(AdQxNd[0]) +"芯)" :"空";
            var bdgl = $XML(BdglNd[0]) != undefined  ? $XML(BdglNd[0]) + "(" +$XML(BdQxNd[0]) +"芯)" :"空";
            
            Res += "<item>";
            Res += "<xh>" + Xh + "</xh>";
            Res += "<adsb>" + $XML(AdBmNd[0]) + "(" +$XML(AdMcNd[0]) +")" + "</adsb>";
            Res += "<addz>" + addz + "</addz>";
            Res += "<adgl>" + adgl + "</adgl>";
            Res += "<bdsb>" + $XML(BdBmNd[0]) + "(" +$XML(BdMcNd[0]) +")" + "</bdsb>";
            Res += "<bddz>" + bddz + "</bddz>";
            Res += "<bdgl>" + bdgl + "</bdgl>";
            Res += "</item>";
        }
        break; 
    }
    Res += "</items>";
    return Res;
}
function IsDsQ(xml)
{
    var flag = true;
    var XmlDoc = CtnXML.getXmlDoc();
     
    if (xml.indexOf("<?xml") == -1)
    {
        xml = "<?xml version='1.0' encoding='gb2312' ?> " + xml;
    }
    try
    {
        XmlDoc.loadXML(xml);
    }
    catch (e)
    {
        CtnDlg.msg("xml数据不符合规范！");
        return false;
    }
    var nodes = XmlDoc.selectNodes("items/item")
    var node = nodes[0];
    var lynodes = node.selectNodes("ly");
    if(lynodes.length > 1)
    {
        var lynode11 = lynodes[0]; 
        var lynode22 = lynodes[1]; 
        var AdBmNd11 = lynode11.selectNodes("adbm")
        var AdBmNd22 = lynode22.selectNodes("adbm")
        if($XML(AdBmNd11[0]) == $XML(AdBmNd22[0]))
        {
            vType = 0;
            flag = true;
        }
        else
        {
            vType = 1
            flag = false;
        }
    }
    else
    {
        vType = 1
        flag = false
    }
    return flag
}